<%@ page language="java" contentType="text/html; charset=UTF-8"	 pageEncoding="UTF-8"%>
<%@ include file="../include/laypublic.jsp"%>
<!DOCTYPE html>
<html>
<head>
  <title>数据字典管理</title>
</head>
<body>
  <div class="layui-fluid">   
    <div class="layui-card">
      <!-- 查询区域  -->
      <div id="query-form" class="layui-form layui-card-header layuiadmin-card-header-auto">
        <div class="layui-form-item">
          <div class="layui-inline">
            <label class="layui-form-label">组编号</label>
            <div class="layui-input-inline">
              <input type="text" name="sgroupNo" placeholder="请输入" autocomplete="off" class="layui-input">
            </div>
          </div>
          <div class="layui-inline">
            <label class="layui-form-label">组名称</label>
            <div class="layui-input-inline">
              <input type="text" name="sgroupName" placeholder="请输入" autocomplete="off" class="layui-input">
            </div>
          </div>
          <div class="layui-inline">
			<label class="layui-form-label">修改类型</label>
		    <div class="layui-input-inline">
		    	<select name="bisModify" id="query-form-bisModify" >
      				<option value="" selected="selected">请选择-修改类型</option>
			        <option value="1">可修改</option>   
   					<option value="0">不可修改</option> 
	      		</select>
		    </div>
	  	  </div>
          <shiro:hasPermission name="PARAMGR_QUERYPARAMGROUP">
	          <div class="layui-inline">
	            <button class="layui-btn layuiadmin-btn-admin" lay-submit lay-filter="LAY-param-group-search">
	              <i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>查询
	            </button>
	            <button class="layui-btn layuiadmin-btn-admin" lay-submit lay-filter="LAY-user-back-reset">
	              <i class="layui-icon layui-icon-fonts-clear  layuiadmin-button-btn"></i>重置
	            </button>
	          </div>
          </shiro:hasPermission>
        </div>
      </div>
  	  <!-- 按钮区域  -->
      <div class="layui-card-body">
        <div style="padding-bottom: 10px;">
          <shiro:hasPermission name="PARAMGR_ADDPARAMGROUP">
          	<button class="layui-btn layuiadmin-btn-admin" data-type="add">
          	 <i class="layui-icon layui-icon-add-1 layuiadmin-button-btn"></i>新增
          	</button>
          </shiro:hasPermission>
          <shiro:hasPermission name="ZKP_DATADICT">
          	<button class="layui-btn layuiadmin-btn-admin" onclick="refreshCache()">
          	 <i class="layui-icon layui-icon-refresh-3 layuiadmin-button-btn"></i>刷新缓存
          	</button>
          </shiro:hasPermission>
        </div>
        <!-- 数据表单 -->
        <table id="LAY-param-group-manage" lay-filter="LAY-param-group-manage"></table>
        
        <div class="layui-form" lay-filter="add_from" id="add_from" style="padding: 20px 30px 0 0;display:none">
		    <div class="layui-form-item">
		      <label class="layui-form-label">组编号</label>
		      <div class="layui-input-inline">
		        <input type="text" name="sgroupNo" maxlength="100" readonly="readonly" placeholder="组编号自动生成，无需填写" autocomplete="off" class="layui-input">
		      </div>
		    </div>
		    <div class="layui-form-item">
		      <label class="layui-form-label">组名称</label>
		      <div class="layui-input-inline">
		        <input type="text" name="sgroupName" maxlength="100" lay-verify="required" placeholder="请输入组名称" autocomplete="off" class="layui-input">
		      </div>
		    </div>
		    <div class="layui-form-item">
		    	<label class="layui-form-label">是否可修改</label>
			    <div class="layui-input-inline">
			    	<select id="add_from-bisModify" name="bisModify" lay-verify="required">
			    		<option value="" selected="selected">请选择</option>
						<option value="1">可修改</option>
    					<option value="0">不可修改</option>  
					</select>
			    </div>
		  	</div>
		    <div class="layui-form-item">
		      <label class="layui-form-label">说明</label>
		      <div class="layui-input-block">
		        <textarea name="sremark" maxlength="100" placeholder="请输入说明" class="layui-textarea"></textarea>
		      </div>
		    </div>
		    <div class="layui-form-item layui-hide">
		      <input type="button" lay-submit lay-filter="add_from_submit" id="add_from_submit" value="确认">
		    </div>
	  	</div>
	  	
	  	<!-- 参数集合明细window -->
        <div class="layui-form" lay-filter="edit_from" id="edit_from" style="padding: 20px 30px 0 0;display:none">
        	<input type="hidden" name="id" />
	 		<input type="hidden" name="sgroupid" />
		    <div class="layui-form-item">
		      <label class="layui-form-label">组编号</label>
		      <div class="layui-input-inline">
		        <input type="text" name="sgroupNo" maxlength="100" readonly="readonly" placeholder="组编号自动生成，无需填写" autocomplete="off" class="layui-input">
		      </div>
		    </div>
		    <div class="layui-form-item">
		      <label class="layui-form-label">组名称</label>
		      <div class="layui-input-inline">
		        <input type="text" name="sgroupName" maxlength="100" lay-verify="required" placeholder="请输入组名称" autocomplete="off" class="layui-input">
		      </div>
		    </div>
		    <div class="layui-form-item">
		    	<label class="layui-form-label">是否可修改</label>
			    <div class="layui-input-inline">
			    	<select name="bisModify" lay-verify="required">
						<option value="1">可修改</option>
    					<option value="0">不可修改</option>  
					</select>
			    </div>
		  	</div>
		    <div class="layui-form-item">
		      <label class="layui-form-label">说明</label>
		      <div class="layui-input-block">
		        <textarea name="sremark" maxlength="100" placeholder="请输入说明" class="layui-textarea"></textarea>
		      </div>
		    </div>
		    <div class="layui-form-item layui-hide">
		      <input type="button" lay-submit lay-filter="edit_from_submit" id="edit_from_submit" value="确认">
		    </div>
		    
		    <!-- 数据字典明细table -->
        	<table id="LAY-param-group-detail" lay-filter="LAY-param-group-detail"></table>
	  	</div>
	  	
	  	<!-- 新增明细window -->
	  	<div class="layui-form" lay-filter="add_detail_from" id="add_detail_from" style="padding: 20px 30px 0 0;display:none">
	  		<input type="hidden" name="sgroupid" id="sgroupid"/>
		    <div class="layui-form-item">
		      <label class="layui-form-label">参数名称</label>
		      <div class="layui-input-inline">
		        <input type="text" name="sname" maxlength="100" lay-verify="required" placeholder="请输入参数名称" autocomplete="off" class="layui-input">
		      </div>
		    </div>
		    <div class="layui-form-item">
		      <label class="layui-form-label">参数值</label>
		      <div class="layui-input-inline">
		        <input type="text" name="svalue" maxlength="300" lay-verify="required" placeholder="请输入参数值" autocomplete="off" class="layui-input">
		      </div>
		    </div>
		    <div class="layui-form-item">
		      <label class="layui-form-label">排序号</label>
		      <div class="layui-input-inline">
		        <input type="text" name="isort" maxlength="40" lay-verify="required|number" placeholder="请输入排序号" autocomplete="off" class="layui-input">
		      </div>
		    </div>
		    <div class="layui-form-item">
		      <label class="layui-form-label">说明</label>
		      <div class="layui-input-block">
		        <textarea name="sremark" maxlength="100" placeholder="请输入说明" class="layui-textarea"></textarea>
		      </div>
		    </div>
		    <div class="layui-form-item layui-hide">
		      <input type="button" lay-submit lay-filter="add_detail_from_submit" id="add_detail_from_submit" value="确认">
		    </div>
	  	</div>
	  	<!-- 编辑明细window -->
	  	<div class="layui-form" lay-filter="edit_detail_from" id="edit_detail_from" style="padding: 20px 30px 0 0;display:none">
	  		<input type="hidden" name="id" />
	  		<input type="hidden" name="sgroupid" id="sgroupid"/>
		    <div class="layui-form-item">
		      <label class="layui-form-label">参数名称</label>
		      <div class="layui-input-inline">
		        <input type="text" name="sname" maxlength="100" lay-verify="required" placeholder="请输入参数名称" autocomplete="off" class="layui-input">
		      </div>
		    </div>
		    <div class="layui-form-item">
		      <label class="layui-form-label">参数值</label>
		      <div class="layui-input-inline">
		        <input type="text" name="svalue" maxlength="300" lay-verify="required" placeholder="请输入参数值" autocomplete="off" class="layui-input">
		      </div>
		    </div>
		    <div class="layui-form-item">
		      <label class="layui-form-label">排序号</label>
		      <div class="layui-input-inline">
		        <input type="text" name="isort" maxlength="40" lay-verify="required|number" placeholder="请输入排序号" autocomplete="off" class="layui-input">
		      </div>
		    </div>
		    <div class="layui-form-item">
		      <label class="layui-form-label">说明</label>
		      <div class="layui-input-block">
		        <textarea name="sremark" maxlength="100" placeholder="请输入说明" class="layui-textarea"></textarea>
		      </div>
		    </div>
		    <div class="layui-form-item layui-hide">
		      <input type="button" lay-submit lay-filter="edit_detail_from_submit" id="edit_detail_from_submit" value="确认">
		    </div>
	  	</div>
      </div>
    </div>
  </div>
	<script type="text/html" id="table-toolbar-addDetail">
        <div class="layui-btn-container">
            <button class="layui-btn layui-btn-sm" lay-event="addDetail">
				<i class="layui-icon layui-icon-add-1 layuiadmin-button-btn"></i>新增
	        </button>
       	</div>
  	</script>
  <script>
  layui.config({
    base: '${ctx}/resources/layuiadmin/' //静态资源所在路径
  }).extend({
    index: 'lib/index' //主入口模块
  }).use(['index', 'table', 'set', 'transfer'], function(){
    var $ = layui.$
    ,form = layui.form
    ,table = layui.table;
    table.render({
      elem: '#LAY-param-group-manage'
      ,url: basePath + '/paraMgr/queryParamGroup' //请求数据接口
      ,cols: [[
        {type: 'checkbox', fixed: 'left'}
        ,{field: 'sgroupNo', title: '组编号'}
        ,{field: 'sgroupName', title: '组名称'}
        ,{field: 'sremark', title: '说明'}
        ,{field: 'bisModify', title: '是否可修改', templet: function(d){
    		  return d.bisModify == '1' ? '可修改' : '不可修改';
    		}
        }
        ,{title: '操作', width: 250, align:'center', fixed: 'right', templet: function(d){
	      	  	var optStr ="";
	      	  	<shiro:hasPermission name="PARAMGR_UPPARAMGROUP">
		      		optStr += '<a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="edit"><i class="layui-icon layui-icon-edit"></i>参数集合明细</a>';
	  	  	  	</shiro:hasPermission>
	  	  	  	<shiro:hasPermission name="PARAMGR_DELPARAMGROUP">
	  	    		 optStr += '<a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del"><i class="layui-icon layui-icon-delete"></i>删除</a>';
	  		  	</shiro:hasPermission>
	  		  	return optStr;
        	}
        }
      ]]
      ,page: true
      ,limit: 10
    });
    
    <shiro:hasPermission name="PARAMGR_QUERYPARAMGROUP">
	    //监听搜索
	    form.on('submit(LAY-param-group-search)', function(data){
	      //执行重载
	      table.reload('LAY-param-group-manage', {page: {curr: 1},
	        where: trimData(data)
	      });
	    });
	    //重置清空
	    form.on('submit(LAY-user-back-reset)', function(data){
	    	reset_form('query-form');
	    	//额外处理select
			$("#query-form-bisModify").val('');
	    });
    </shiro:hasPermission>
    
 	// 明细table监听操作列
    table.on('tool(LAY-param-group-detail)', function(obj){
      var data = obj.data;
      if(obj.event === 'delDetail'){
          layer.confirm('确定删除？',{icon:3, title :'提示'}, function(index){
            	$.ajax({
    				type : 'post',
    				url : basePath + '/paraMgr/delParamGroupDetail?checkboxId=' + data.id,
    				success:function(result){
    					if(result.success){
    						table.reload('LAY-param-group-detail'); //数据刷新
    						layer.close(index);
    					}else{
    						layer.msg(result.msg,{icon: 7});
    				  	}
    				}
    			});
            });
        }else if(obj.event === 'editDetail'){
        	form.val('edit_detail_from',data); // 填充原值
        	layer.open({
	        	  type: 1
	        	  ,title: '编辑明细'
	        	  ,content: $('#edit_detail_from')
	        	  ,area: layui.admin.screen() < 2 ? ['80%', '410px'] : ['420px','410px']
	        	  ,btn: ['确定', '取消']
	        	  ,btnAlign: 'c'
	        	  ,yes: function(index, layero){
	        		  var submitID = 'edit_detail_from_submit'
	            		,submit = layero.contents().find('#'+ submitID);
	        		  //监听提交
	        		  form.on('submit('+ submitID +')', function(data){
	        			  var field = data.field; //获取提交的字段
	        			  //提交 Ajax 成功后，静态更新表格中的数据
	        			  $.ajax({
	        				  type : 'post',
	        				  url : basePath + '/paraMgr/updateParamGroupDetail',
	        				  data: field,
	        				  success:function(result){
	        					  if(result.success){
	        						  table.reload('LAY-param-group-detail'); //数据刷新
	        						  layer.close(index); //关闭弹层
	        						  clean_form("edit_detail_from");//清空表单
	        					  }else{
	        						  layer.msg(result.msg,{icon: 7});
	        					  }
	        				  }
	              		 });
	            	});  
	            submit.trigger('click');
	          }
	        });
        }
    });
 	// 明细table监听toolbar
    table.on('toolbar(LAY-param-group-detail)', function(obj){
      	var data = obj.data;
      	if(obj.event === 'addDetail'){
      		layer.open({
	        	  type: 1
	        	  ,title: '添加明细'
	        	  ,content: $('#add_detail_from')
	        	  ,area: layui.admin.screen() < 2 ? ['80%', '410px'] : ['420px','410px']
	        	  ,btn: ['确定', '取消']
	        	  ,btnAlign: 'c'
	        	  ,yes: function(index, layero){
	        		  var submitID = 'add_detail_from_submit'
	            		,submit = layero.contents().find('#'+ submitID);
	        		  //监听提交
	        		  form.on('submit('+ submitID +')', function(data){
	        			  var field = data.field; //获取提交的字段
	        			  //提交 Ajax 成功后，静态更新表格中的数据
	        			  $.ajax({
	        				  type : 'post',
	        				  url : basePath + '/paraMgr/addParamGroupDetail',
	        				  data: field,
	        				  success:function(result){
	        					  if(result.success){
	        						  table.reload('LAY-param-group-detail'); //数据刷新
	        						  layer.close(index); //关闭弹层
	        						  clean_form("add_detail_from");//清空表单
	        					  }else{
	        						  layer.msg(result.msg,{icon: 7});
	        					  }
	        				  }
	              		 });
	            	});  
	            submit.trigger('click');
	          }
	        });
      	}
    });
    // 监听操作列
    table.on('tool(LAY-param-group-manage)', function(obj){
      var data = obj.data;
      if(obj.event === 'del'){
          layer.confirm('确定删除？',{icon:3, title :'提示'}, function(index){
          	$.ajax({
  				type : 'post',
  				url : basePath + '/paraMgr/delParamGroup?checkboxId=' + data.id,
  				success:function(result){
  					if(result.success){
  						table.reload('LAY-param-group-manage'); //数据刷新
  						layer.close(index);
  					}else{
  						layer.msg(result.msg,{icon: 7});
  				  	}
  				}
  			});
          });
      }else if(obj.event === 'edit'){
      	form.val('edit_from',data); // 填充原值
      	$('input[name=sgroupid]').val(data.id);
     	//参数集合table渲染
        table.render({
          elem: '#LAY-param-group-detail'
          ,url: basePath + '/paraMgr/queryParamGroupDetail?sgroupid='+data.id //请求数据接口
          ,toolbar:'#table-toolbar-addDetail'
          ,defaultToolbar: []
          ,cols: [[
            {type: 'checkbox', fixed: 'left'}
            ,{field: 'sname', title: '参数名称'}
            ,{field: 'svalue', title: '参数值'}
            ,{field: 'sremark', title: '说明'}
            ,{field: 'isort', title: '排序号',width: 95}
            ,{title: '操作', width: 171, align:'center', fixed: 'right', templet: function(d){
    	      	  	var optStr ="";
    	  	  	  	<shiro:hasPermission name="PARAMGR_UPPARAMGROUP">
    	  	    		 optStr += '<a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="editDetail"><i class="layui-icon layui-icon-edit"></i>编辑</a>';
    	  		  	</shiro:hasPermission>
    	  	  	  	<shiro:hasPermission name="PARAMGR_DELPARAMGROUP">
    	  	    		 optStr += '<a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="delDetail"><i class="layui-icon layui-icon-delete"></i>删除</a>';
    	  		  	</shiro:hasPermission>
    	  		  	return optStr;
            	}
            }
          ]]
          ,page: true
          ,limit: 10
        });
      	layer.open({
            type: 1
            ,title: '参数集合明细'
            ,content: $('#edit_from')
            ,area: layui.admin.screen() < 2 ? ['80%', '560px'] : ['900px','560px']
            ,btn: ['确定', '取消']
            ,btnAlign: 'c'
            ,yes: function(index, layero){
          	  var submitID = 'edit_from_submit'
          		  ,submit = layero.contents().find('#'+ submitID);
          	  //监听提交
          	  form.on('submit('+ submitID +')', function(data){
                var field = data.field; //获取提交的字段
                //提交 Ajax 成功后，静态更新表格中的数据
                $.ajax({
                    type : 'post',
  					url : basePath + '/paraMgr/updateParamGroup',
                    data: field,
  					success:function(result){
  						if(result.success){
                			table.reload('LAY-param-group-manage'); //数据刷新
                			layer.close(index); //关闭弹层
                			clean_form('edit_from');//清空表单
  						}else{
  							layer.msg(result.msg,{icon: 7});
  					  	}
  					}
                });
              });  
              submit.trigger('click');
            }
          });
        }
    });
    
    // 按钮事件
    var active = {
      add: function(){
          layer.open({
        	  type: 1
        	  ,title: '添加数据字典'
        	  ,content: $('#add_from')
        	  ,area: layui.admin.screen() < 2 ? ['80%', '410px'] : ['420px','410px']
        	  ,btn: ['确定', '取消']
        	  ,btnAlign: 'c'
        	  ,yes: function(index, layero){
        		  var submitID = 'add_from_submit'
            		,submit = layero.contents().find('#'+ submitID);
        		  //监听提交
        		  form.on('submit('+ submitID +')', function(data){
        			  var field = data.field; //获取提交的字段
        			  //提交 Ajax 成功后，静态更新表格中的数据
        			  $.ajax({
        				  type : 'post',
        				  url : basePath + '/paraMgr/addParamGroup',
        				  data: field,
        				  success:function(result){
        					  if(result.success){
        						  table.reload('LAY-param-group-manage'); //数据刷新
        						  layer.close(index); //关闭弹层
        						  clean_form("add_from");//清空表单
        						  //额外处理select
        						  $("#add_from-bisModify").val('');
        						  form.render("select");
        					  }else{
        						  layer.msg(result.msg,{icon: 7});
        					  }
        				  }
              		 });
            	});  
            submit.trigger('click');
          }
        }); 
      }
    } 
    // data-type事件
    $('.layui-btn.layuiadmin-btn-admin').on('click', function(){
      var type = $(this).data('type');
      active[type] ? active[type].call(this) : '';
    });
  });
  
	//刷新缓存
	function refreshCache(){
		layui.$.ajax({
		  type : 'post',
		  url : '${ctx}/zkpPath/dataDic',
		  success:function(result){
			  if(result.success){
				  layer.alert(result.msg, {icon:1});
			  }else{
				  layer.msg(result.msg, {icon:7});
			  }
		  }
	  });
	}
  </script>
</body>
</html>

